﻿using SpaceNeedle.SDK.Windows.Platform.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SpaceNeedle.x6473.WindowsPhone.Common
{
    public class NetworkServiceBase : ModelBase
    {
        protected bool wasConnectedOnceBefore;
        protected bool isConnected;
        protected bool isVerifyingConnection = false;
        protected bool isHandlingStatus = false;

        public event EventHandler Disconnected = delegate { };
        public event EventHandler Connected = delegate { };
        public event EventHandler Reconnected = delegate { };
        public event EventHandler StatusChanged = delegate { };

        protected void OnStatusChanged()
        {
            this.StatusChanged(null, null);
        }

        protected void OnDisconnected()
        {
            this.Disconnected(null, null);
            this.OnStatusChanged();
        }

        protected void OnConnected()
        {
            this.Connected(null, null);
            this.OnStatusChanged();
        }

        protected void OnReconnected()
        {
            this.Reconnected(null, null);
            this.OnStatusChanged();
        }

        public bool IsConnected
        {
            get { return this.Get<bool>(); }
            protected set { this.Set(value); }
        }

        public virtual void HandleState()
        {
            throw new NotImplementedException("NetworkService.HandleState must be implemented");
        }
    }
}
